﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using WSPDocumentBuilder_WPF.Managers;

namespace WSPDocumentBuilder_WPF.BLL
{
    public class WSPDocumentationInfo
    {
        public string WspFullPath { get; set; }

        private string _wspName = string.Empty;
        /// <summary>
        /// Nom du WSP
        /// </summary>
        public string WspName
        {
            get
            {
                if (string.IsNullOrEmpty(_wspName))
                {
                    _wspName = System.IO.Path.GetFileNameWithoutExtension(WspFullPath);
                }

                return _wspName;
            }
        }

        private string _extractionPath = string.Empty;
        /// <summary>
        /// Dossier d'extraction du WSP
        /// </summary>
        public string ExtractionPath
        {
            get
            {
                if (string.IsNullOrEmpty(_extractionPath))
                {
                    _extractionPath = LocationManager.DataPath + @"\" + WspName;
                }

                return _extractionPath;
            }
        }

        private string _manifestPath = string.Empty;
        /// <summary>
        /// Localisation du fichier manifest
        /// </summary>
        public string ManifestPath
        {
            get
            {
                if (string.IsNullOrEmpty(_manifestPath))
                {
                    _manifestPath = ExtractionPath + @"\manifest.xml";
                }

                return _manifestPath;
            }
        }

        private string _excelXmlFilePath = string.Empty;
        /// <summary>
        /// Chemin du fichier de documentation ExcelXml
        /// </summary>
        public string ExcelXmlFilePath
        {
            get
            {
                if (string.IsNullOrEmpty(_excelXmlFilePath))
                {
                    _excelXmlFilePath = LocationManager.DataPath + @"\" + WspName + @"-documentation.xml";
                }

                return _excelXmlFilePath;
            }
        }

        private string _xmlFilePath = string.Empty;
        /// <summary>
        /// Chemin du fichier de documentation xml
        /// </summary>
        public string XmlFilePath
        {
            get
            {
                if (string.IsNullOrEmpty(_xmlFilePath))
                {
                    _xmlFilePath = LocationManager.DataPath + @"\" + WspName + @".xml";
                }

                return _xmlFilePath;
            }
        }

        /// <summary>
        /// Création d'une instance à partir du chemin du WSP
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static WSPDocumentationInfo FromFilePath(string filePath)
        {
            WSPDocumentationInfo result = new WSPDocumentationInfo()
            {
                WspFullPath = filePath
            };

            return result;
        }
    }
}
